package bsf.baseservice.businessmq.systemruntime.log;

import bsf.baseservice.businessmq.dal.tb_error_dal;
import bsf.baseservice.businessmq.model.tb_error_model;
import bsf.baseservice.businessmq.systemruntime.ConfigHelper;
import bsf.db.DbConn;
import bsf.util.ConvertUtil;
import bsf.util.ExceptionUtil;
import org.apache.commons.lang3.StringUtils;
public class ErrorLogHelper
{
    public static void writeLine(int mqpathid, String mqpath, String methodname, String msg, Exception exp)
    {
        if (!StringUtils.isEmpty(ConfigHelper.LogDBConnectString))
        {
            try
            {
                try(DbConn c = DbConn.createConn(ConfigHelper.LogDBConnectString))
                {
                    tb_error_dal dal = new tb_error_dal();
                    tb_error_model t = new tb_error_model();
                    t.createtime=new java.util.Date();
                    t.info=String.format("错误:%1$s,exp:%2$s", ConvertUtil.nullToStr(msg), ConvertUtil.nullToStr(ExceptionUtil.getDetailMessage( exp)));
                    t.mqpath=ConvertUtil.nullToStr(mqpath);
                    t.mqpathid=mqpathid;
                    t.methodname=ConvertUtil.nullToStr(methodname);
                    dal.add(c, t);
                }
            }
            catch (Exception e1)
            {
				/* 临时注释
				XXF.Log.ErrorLog.Write(String.format("BusinessMQ插入错误信息时发生错误,mqpathid:%1$s,mqpath:%2$s,methodname:%3$s,msg:%4$s",
						mqpathid, mqpath.NullToEmpty(), methodname.NullToEmpty(), msg.NullToEmpty()), e1);*/
            }
        }
        else
        {/* 临时注释
			XXF.Log.ErrorLog.Write(String.format("BusinessMQ错误,mqpathid:%1$s,mqpath:%2$s,methodname:%3$s,msg:%4$s",
			mqpathid,mqpath.NullToEmpty(),methodname.NullToEmpty(),msg.NullToEmpty()), exp);*/
        }
        DebugHelper.writeLine(mqpathid, mqpath, methodname, "【出错】:" + msg+"exp:"+exp.getMessage()+"strace:"+ ExceptionUtil.getFullMessage(exp));
    }
}